JBoss Community Archive (Read Only)

RHQ 4.7

Script Sources

Existing impls

Note that the filename extension of the modules can be omitted for both javascript and python, but this is generally lanaguage-specific:

Repositories

Module ID format

rhq://repositories/<repo_name>/<module_name>

Description

Requires a user to be logged in to RHQ server. Downloads a module of given name from a repository of given name.

Javascript Example

var myModule = require("rhq://repositories/myRepo/myModule"); //This will load the module stored in the RHQ server repository "myRepo" called "myModule.js"

Available In

CLI, server

Implementation class

RepoScriptSourceProvider

File System

Module ID format

file:<absolute-path>

Description

Allows for loading modules from absolute paths on the local filesystem.

Javascript Example

var myModule = require("file:/opt/jon/js-modules/myModule"); //This will load the module from a file called "myModule.js" in the /opt/jon/js-modules directory on the local filesystem.

Available In

CLI

Implementation class

FileSystemScriptSourceProvider

Downloads

Module ID format

rhq://downloads/<path-to-module>

Description

Requires a user to be logged in to RHQ server. Downloads a module of given name from a "downloads" location on the RHQ server. The idea for this location is that in this location you will find scripts provided by RHQ itself that can be used both by the alert scripts and the CLI.

Javascript Example

var myModule = require("rhq://downloads/js/util"); //This will load the module stored in the RHQ server downloads section called "js/util.js"

Available In

CLI, server

Implementation class

RhqDownloadsScriptSourceProvider for the CLI version and RhqDownloadsScriptSourceProvider for the server-side version

Modules Directory

Module ID format

modules:<path>

Description

Allows for loading modules from a configured location on the local filesystem. You can configure the root location by passing rhq.scripting.modules.root-dir system property to the CLI process. E.g.

RHQ_CLI_ADDITIONAL_JAVA_OPTS='-Drhq.scripting.modules.root-dir=/opt/rhq/modules' bin/rhq-cli.sh

Javascript Example

var myModule = require("modules:/myCompany/production/serverLocations"); //This will load the module from a file called "serverLocations.js" from a file that is located in the "myCompany/production" directory under a configured "root-dir" location.

Available In

CLI

Implementation class

ModulesDirectoryScriptSourceProvider

How it works

RHQ has a pluggable mechanism for locating scripts in various locations.

To add support for your location of choice, you need to implement the ScriptSourceProvider interface and put the Java service entry in META-INF/services of a jar your class is located in. Then you need to put this jar into $CLI_HOME/lib or on the server into $RHQ_HOME/jbossas/server/default/deploy/rhq.ear/lib.

Example

Above we listed several existing implementations of the org.rhq.scripting.ScriptSourceProvider interface. This is a simple one method interface that you can implement yourself to provide new locations the scripts can be downloaded from.

For example the following implementation just tries to download the script from the URI if Java supports connecting to that location (i.e. it will support at least http and https protocols):

public class URLScriptSourceProvider implements ScriptSourceProvider {

    public Reader getScriptSource(URI scriptUri) {
        if (scriptUri == null) {
            return null;
        }

        try {
            return new InputStreamReader(scriptUri.toURL().openStream());
        } catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
}

To install this source provider into CLI, you can use the Java services functionality. In the META-INF directory of the jar where you provider resides, create the "services" directory and in there, create a file called org.rhq.scriting.ScriptSourceProvider. In that file, place the full class names of any source providers you implemented in the jar, one per line. If the URLScriptSourceProvider from above was from the com.example package, this would be the layout of the jar:

  • com

    • example

      • URLScriptSourceProvider.class

  • META-INF

    • services

      • org.rhq.scripting.ScriptSourceProvider

and the file META-INF/services/org.rhq.scripting.ScriptSourceProvider would contain just a single line:

com.example.URLScriptSourceProvider

You'd put this jar into the lib directory of your CLI installation and you could start using it in your require calls. For example the following javascript code would cause the provider to download the file from the network:

var myModule = require("http://intranet.my-company.com/rhq-scripts/stuff.js");

If you'd like to use this source provider in your alert scripts on the RHQ server, you'd need to place the jar in the jbossas/server/default/deploy/rhq.ear/lib of the RHQ server
installation.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-12 13:58:26 UTC, last content change 2012-10-26 09:44:27 UTC.